/******************************************************************************
* SVN­Version­Information:
* ­­­­­­­­­­­­­­­­­­­­­­­­---------------------
* $LastChangedRevision: 6 $
* $LastChangedBy: c.a.duevel $
* $LastChangedDate: 2009-08-26 15:12:37 +0000 (Wed, 26 Aug 2009) $
* $HeadURL: http://robofight.googlecode.com/svn/trunk/ClientJavaFX/src/de/hft_stuttgart/robofight/client/javafx/util/TableEntry.fx $
******************************************************************************/
package de.hft_stuttgart.robofight.client.javafx.util;


import javafx.ext.swing.SwingLabel;
import javafx.scene.Cursor;
import javafx.scene.CustomNode;
import javafx.scene.effect.Effect;
import javafx.scene.Group;
import javafx.scene.input.MouseEvent;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import de.hft_stuttgart.robofight.client.javafx.Constants;
import com.sun.javafx.scene.control.caspian.ButtonSkin;

/**
 * @author ralf.dauenhauer@gmx.de
 * Utility class TableEntry
 */
public class TableEntry extends CustomNode {

    public var x: Number;
    public var y: Number;
    public var group:Group;
    public var getNodeByName : function(nodeName : String) : Node;
    public var text : String;
    var showTooltip = false;
    public var entryAction : function() : Void;
    public var tooltipAction : function() : String;
    public var setAction : function(robotID : Integer) : Void;
    public var infoBox : Node;
    public var statusLight : Node;
    public var entryID : Integer;
    var status : Boolean = true;
    var tooltipText : String = "";
    public var toolTip : Boolean = true;
    public var textColumns : Integer = 150;
    public var switching : Boolean = true;
    public var font : Font = Constants.FONT_TEXTFIELD;
    public var kickPlayer : Boolean = false;
    public var playerID : String;
    public var fontColor : Color = Color.WHITE;

    var statusLightGroup : Group = Group {
        content : bind statusLight;
    }

   var kickButton = javafx.scene.control.Button {
        cursor: Cursor.HAND
        text: "Kick"
        font: Constants.FONT_TEXTFIELD
        layoutX : infoBox.layoutBounds.maxX - 55
        width: 50 height: 22
        onMouseClicked: function( e: MouseEvent ):Void {
            setAction(0);
        }
        visible : bind kickPlayer
        skin: ButtonSkin {
            borderFill: Color.BLACK
            cornerRadius: 15
            highlightFill: Color.BLACK
            shadowFill: Color.BLACK
            textFill: Color.BLACK
            fill: Color.GRAY
        }
    }


    var tableEntry : Group = Group {
            layoutX: x + 5
            layoutY: y
            cursor: Cursor.HAND
            content: [
                infoBox,
                statusLightGroup,
                SwingLabel {
                    layoutX: 20
                    text: bind text
                    width: bind textColumns
                    height : 20
                    font: bind font
                    foreground : bind fontColor
                }, kickButton
            ]
            onMouseEntered : function( e: MouseEvent ):Void {
                tooltipText = tooltipAction();
                showTooltip = true;
            }
            onMouseExited: function( e: MouseEvent ):Void {
                showTooltip = false;
            }
            onMouseClicked:  function( e: MouseEvent ):Void {
                entryAction();
                if(switching) {
                    switchStatus();
                }
            }
         };

  
    public function switchStatus(){
        if(status){
            statusLight = getNodeByName("greenLight");
            if (setAction != null){
                setAction(entryID);
            }
            status = false;
        } else {
            statusLight = getNodeByName("redLight");
            if (setAction != null){
                setAction(entryID);
            }
            status = true;
        }
    }

    init {
        if(toolTip == true){
            insert Tooltip{
               x : 30;
               y : -20;
               text : bind tooltipText;
               visible : bind showTooltip;
            } into tableEntry.content;
        }
    }


    override public function create():Node {
        return Group {
            content: [
                tableEntry
            ]
        }
    }
}
